/**
 * @author wcj
 * @Date 2021/6/8 11:01
 * @Version 1.0
 */
public class Daemon {

    public static void main(String[] args) {
        Thread thread = new Thread(new DaemonRunner(), "DaemonRunner");
        thread.setDaemon(true);
        thread.start();
    }

    /**
     * Daemon为支持型或者说保护型线程：需要在start之前设置为Daemon，并且Daemon线程的关闭是立即终止的
     * 无法通过finally语句进行清理等工作
     */
    static class DaemonRunner implements Runnable {

        @Override
        public void run() {
            try {
                SleepUtils.second(100);
            } finally {
                System.out.println("------------");
            }
        }
    }
}
